package link

import "git.oschina.net/fuxiaohei/fuxiaohei-go.git/Core"

type Home struct {

}

func (_ Home) Setup() {
	Core.SetRoute("GET:/links", "[I]link.Home.ListAction")
	Core.SetRoute("POST:/links/apply", "[I]link.Home.ApplyAction")
}

func (_ Home) ListAction(request *Core.HxRequest, response *Core.HxResponse) {
	b := Core.DoBehavior("user:links.html", request, response)
	t := b.Template()
	t.Share("TITLE", "好友链接")
	t.Share("Links", GetApprovedList())
	t.Js("js/jquery.form.js")
	b.Do()
}

func (_ Home) ApplyAction(request *Core.HxRequest, response *Core.HxResponse) {
	if !request.IsAjax() {
		response.Status = 404
		return
	}
	data := request.Input().All()
	res := map[string]interface {}{"res":false}
	msg := validateLinkData(data, "")
	if msg != "" {
		res["msg"] = msg
		response.Json(res)
		return
	}
	AddPendingLink(data)
	res["res"] = true
	response.Json(res)
}


